package com.wenxixuanwu.fruitstore.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wenxixuanwu.fruitstore.entity.Banner;
import com.wenxixuanwu.fruitstore.service.BackBannerService;
import com.wenxixuanwu.fruitstore.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author :小凡凡
 * @version :1.0
 * @Project :fruitstore
 * @Date :2022/4/22
 */
@RestController
@RequestMapping("/backBanner")
public class BackBannerController extends BaseController{

    @Autowired
    private BackBannerService bannerService;

    @GetMapping("/findBannerAll")
    public JsonResult<List<Banner>> findBannerAll(){
        List<Banner> data = bannerService.findBannerAll();
        return new JsonResult<List<Banner>>(OK,data);
    }

    @PostMapping("/insertBanner")
    public void insertBanner(@RequestBody Banner banner){
        System.out.println(banner);
        bannerService.insertBanner(banner);
    }

    @GetMapping("/deleteBanner/{id}")
    public void deleteBanner(@PathVariable("id") Integer id){
        bannerService.deleteBanner(id);
    }

    //分页
    @GetMapping("/page/{pageCode}/{pageSize}")
    public Page<Banner> findByPage(@PathVariable("pageCode") Integer pageCode,
                                   @PathVariable("pageSize") Integer pageSize){
        Page<Banner> pageInfo = bannerService.findByPageService(pageCode, pageSize);
        return pageInfo;
    }
}
